package cn.jtcoding.order.service.impl.feign;

import cn.jtcoding.common.framework.vo.*;
import cn.jtcoding.common.framework.pagehelper.*;
import cn.jtcoding.item.pojo.dataobject.ItemsDO;
import cn.jtcoding.item.pojo.dataobject.ItemsSpecDO;
import cn.jtcoding.item.pojo.vo.ItemCommentLevelCountVO;
import cn.jtcoding.item.pojo.vo.ItemCommentVO;
import cn.jtcoding.item.pojo.vo.ItemInfoVO;
import cn.jtcoding.item.pojo.vo.ItemSearchVO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import cn.jtcoding.order.service.impl.feign.fallback.ItemFeignFallbackFactory;

/**
 * @author jason.tang
 * @date 2021/3/10 12:22
 * @desc
 */

@FeignClient(
        name = "item-server",
        path = "/items",
        fallbackFactory = ItemFeignFallbackFactory.class)
public interface ItemFeignService {

    @GetMapping("/info/{itemId}")
    ApiResult<ItemInfoVO> getItemInfo(@PathVariable("itemId") String itemId);

    @GetMapping("/commentLevel")
    ApiResult<ItemCommentLevelCountVO> getItemCommentCount(@RequestParam("itemId") String itemId);

    @GetMapping("/comments")
    ApiResult<PagedGridResult<ItemCommentVO>> getItemComments(@RequestParam("itemId") String itemId,
                                                   @RequestParam("level") Integer level,
                                                   @RequestParam("page") Integer page,
                                                   @RequestParam("pageSize") Integer pageSize);

    @GetMapping("/search")
    ApiResult<PagedGridResult<ItemSearchVO>> searchItems(@RequestParam("keywords") String keywords,
                                              @RequestParam("sort") String sort,
                                              @RequestParam("page") Integer page,
                                              @RequestParam("pageSize") Integer pageSize);

    @GetMapping("/spec/{itemSpecId}")
    ApiResult<ItemsSpecDO> queryItemSpecById(@PathVariable("itemSpecId") String itemSpecId);

    @GetMapping("/{itemId}")
    ApiResult<ItemsDO> queryItemById(@PathVariable("itemId") String itemId);

    @GetMapping("/img/{itemId}/main")
    ApiResult<String> queryItemMainImgById(@PathVariable("itemId") String itemId);

    @GetMapping("/spec/{itemSpecId}/dec_stock")
    void decreaseItemSpecStock(@PathVariable("itemSpecId") String itemSpecId, @RequestParam("buyCounts") Integer buyCounts);
}
